/**
 * 
 */
package org.compiere.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

/**
 * @author V.Sokolov
 *
 */
public class MhrmtaxReserve extends X_hrm_taxReserve {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5327943448084489070L;
	
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (MhrmtaxReserve.class);

	/**
	 * @param ctx
	 */
	public MhrmtaxReserve(Properties ctx) {
		super(ctx);
	}

	/**
	 * @param ctx
	 * @param hrm_taxReserve_ID
	 * @param trxName
	 */
	public MhrmtaxReserve(Properties ctx, int hrm_taxReserve_ID, String trxName) {
		super(ctx, hrm_taxReserve_ID, trxName);
	}

	/**
	 * @param ctx
	 * @param rs
	 * @param trxName
	 */
	public MhrmtaxReserve(Properties ctx, ResultSet rs, String trxName) {
		super(ctx, rs, trxName);
	}
	
	public static MhrmtaxReserve getTaxReserve(int C_BPartner_ID, Timestamp dateFrom){
		
		//
	    PreparedStatement pstmt = null;
		ResultSet rs = null;
		MhrmtaxReserve taxR = null;
		
		String sql = "SELECT * FROM HRM_TAXRESERVE WHERE C_BPARTNER_ID="+C_BPartner_ID+" \n" +
					 "AND DATEFROM = DATE_TRUNC('MONTH', "+DB.TO_DATE(dateFrom, true)+")";
		try
		{
			pstmt = DB.prepareStatement(sql,null);			
			rs = pstmt.executeQuery();	
			if(rs.next())
				taxR = new MhrmtaxReserve(Env.getCtx(), rs, null);
		}
		catch (SQLException e)
		{
			s_log.log(Level.SEVERE, "product", e);
		}
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}
		
		return taxR;
	}

}
